/**
 * Created by walkman on 2017/6/22.
 */
'user strict';

(function () {

  angular.module('WfbPlatformApp').controller('RechargeController',
    ['$rootScope', '$scope', '$http', '$compile', 'http', '$q', 'walletService', 'rechargeService',
      function ($rootScope, $scope, $http, $compile, http, $q, walletService, rechargeService) {

        $scope.$on('$viewContentLoaded', function () {
          // initialize core components
        });

        $scope.$on('$includeContentLoaded', function () {
        });

        // 新增参数
        $scope.coinPrice = {};
        $scope.userWallet = {};

        $scope.currentPage = 1;//当前页面
        $scope.pageSize = 10;//页面大小
        $scope.total = 0;
        $scope.contents = {};

        $scope.getCoinPrice = function () {
          var promise = walletService.getCoinPrice({});
          promise.then(function success(result) {
            if (result.retCode == '1') {
              //成功回调
              $scope.coinPrice = result.data.currentPrice;
            }
          }, function error(error) {
            //错误回调
          });
        };

        $scope.getUserWallet = function () {
          var promise = walletService.getUserWallet({});
          promise.then(function success(result) {
            if (result.retCode == '1') {
              //成功回调
              $scope.userWallet = angular.copy(result.data);
            }
          }, function error(error) {
            //错误回调
          });
        };

        $scope.getRechargeRecords = function (pageNo, pageSize) {

          var promise = rechargeService.getRechargeRecords({
            'pageNo': pageNo,
            'pageSize': pageSize
          });
          promise.then(function success(result) {
            // console.log(JSON.stringify(result));
            //成功回调
            $scope.contents = result.data;
            // 分页数
            $scope.total = result.totalCount;
          }, function error(error) {//错误回调
            // console.log(JSON.stringify(error));
          });
        };

        $scope.pageAction = function (message, page, pageSize, total) {

          console.log({
            text: message,
            page: page,
            pageSize: pageSize,
            total: total
          });

          $scope.getRechargeRecords(page, pageSize);
        };

        $scope.getRechargeStatus = function (status) {
          return "成功";
        };

        $scope.getCoinPrice();
        $scope.getUserWallet();
        $scope.getRechargeRecords($scope.currentPage, $scope.pageSize);

      }]
  );

})();

